package eu.tsp.isensors.impl.alert.manager;

import eu.tsp.isensors.services.alert.schema.GeneratedAlerts;
import eu.tsp.isensors.services.alert.schema.AlertType;
import eu.tsp.isensors.services.alert.trigger.AlertService;

import javax.xml.bind.Marshaller;
import javax.xml.bind.JAXBException;
import javax.xml.bind.JAXBContext;

public class AlertManager implements AlertService {
	public AlertManager(){
		System.out.println("new Alert Manager");
	}

	public void start() {
        	System.out.println(" >> start AlertManager");
    	}

    	public void stop() {
        	System.out.println(" >> stop AlertManager");
    	}

	public boolean newAlerts(GeneratedAlerts g){
		try {
			System.out.println("This is newAlerts :))");
			// Déboguagelerts
			JAXBContext jc = JAXBContext.newInstance(eu.tsp.isensors.services.alert.schema.ObjectFactory.class);
			Marshaller m = jc.createMarshaller();
			m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);
        		m.marshal(g ,System.out );
		} catch(JAXBException e){
                	e.printStackTrace();
        	}catch(Exception e){
			e.printStackTrace();
		}
		
		for(AlertType elt:g.getAlerts().getAlert()){
			System.out.println("> newAlerts -- Alert Type :" + elt.getType().value()+" "+elt.getContentType().value()+" "+elt.getDestination()+"  \n"+elt.getMsg()+"\n");
		}
		return true;
	}
}
